package com.demo.demos.convert;

import com.demo.demos.entity.DTO.UserDTO;
import com.demo.demos.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;


/**
 * Created by Lenovo
 * DATA:2024/9/26
 **/
@Mapper
public interface UserMapper {
    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);


    /**
     * 拷贝复制当个实体类
     * @param user
     * @return
     */
    UserDTO userToUserDto(User user);

    /**
     * 针对List 集合中的实体进行拷贝复制
     * @param user
     * @return
     */
    List<UserDTO> userListToUserDtoList(List<User> user);



    @Mapping(target = "phone", qualifiedByName = "addPhoneAndAge")
    List<UserDTO> copyListUserToUserDtoByCustomMappings(List<User> user);
    
    @Named("addPhoneAndAge")
    default String addPhoneAndAge(User user) {
        return user.getPhone() + "-" + user.getAge();
    }
}
